package code5;

import java.util.Collections;
import java.util.List;

public class Code4 {


    public void code(List<Integer> l){

        Collections.sort(l);
        Collections.reverse(l);

        StringBuilder str = new StringBuilder();

        int i1 = 0;
        int i2 = 0;
        int n = 0;
        if(1==l.get(16)){
            for(int i=16; i>=0; i--){
                if(1 == l.get(i)){
                    i1++;
                }else if(2 == l.get(i)){
                    i2++;
                }else{
                    break;
                }
            }
            code2(i1, i2, str, l, n);
        }else if(2==l.get(16)){
            for(int i=16; i>=0; i--){
                if(2 == l.get(i)){
                    i2++;
                }else{
                    break;
                }
            }
            code2(i1, i2, str, l, n);
        }else{
            code2(i1, i2, str, l, n);
        }
        System.out.println("玩家的牌是："+str);
    }

    public void code2(int i1, int i2, StringBuilder str, List<Integer> list, int n){

        if(list.get(0)==14 || list.get(0)==15){
            if(14==list.get(0)){
                str.append("小王,");
                n = 1;
                code1(i1,i2,str,list,n);
            }else if(15==list.get(0)){
                str.append("大王,");
                if(14==list.get(1)){
                    str.append("小王,");
                    n = 2;
                    code1(i1,i2,str,list,n);
                }else{
                    n = 1;
                    code1(i1,i2,str,list,n);
                }
            }
        }else{
            code1(i1,i2,str,list,n);
        }
    }

    public void code1(int i1, int i2, StringBuilder str, List<Integer> list, int n){

        for(int i=0; i<i2; i++){
            str.append("2,");
        }
        for(int j=0; j<i1; j++){
            str.append("A,");
        }
        for(int k=n; k<(17-i1-i2); k++){
            if((16-i1-i2)==k){
                if(11==list.get(k)){
                    str.append("J");
                }else if(12==list.get(k)){
                    str.append("Q");
                }else if(13==list.get(k)){
                    str.append("K");
                }else{
                    str.append(list.get(k)+"");
                }
            }else{
                if(11==list.get(k)){
                    str.append("J,");
                }else if(12==list.get(k)){
                    str.append("Q,");
                }else if(13==list.get(k)){
                    str.append("K,");
                }else{
                    str.append(list.get(k)+",");
                }
            }
        }
    }
}
